package com.k1998.mybatis.service.impl;

import com.k1998.mybatis.bean.JxCloud;
import com.k1998.mybatis.dao.IJxCloudDao;
import com.k1998.mybatis.service.JxCloudService;
import com.k1998.mybatis.utils.HashMapUtils;
import com.k1998.mybatis.utils.QueryInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ChenYuxiang
 * @Description: //JxCloudImpl
 * @Param:
 * @return:
 * @Date: 17:13 2021/2/7
 **/
@Service("JxCloudService")
public class JxCloudImpl implements JxCloudService {
    @Autowired
    private IJxCloudDao iJxCloudDao;
    @Override
    public String getAllJxClouds(QueryInfo queryInfo) {
        if(null==queryInfo.getQuery()){queryInfo.setQuery("");}
        if(queryInfo.getDisplay() >1 || queryInfo.getDisplay() < -1) {queryInfo.setDisplay(-1);}
        int numbers = iJxCloudDao.getCounts("%"+queryInfo.getQuery()+"%",queryInfo.getDisplay());
        int pageStart = (queryInfo.getPageNum()-1)*queryInfo.getPageSize();
        List<JxCloud> jx = iJxCloudDao.findAll("%"+queryInfo.getQuery()+"%",queryInfo.getDisplay(),pageStart,queryInfo.getPageSize());
        return HashMapUtils.toHashMap(numbers,jx);
    }
}
